﻿using System;
using System.Web.UI;
using Ajax.Tools.Security;

namespace Ajax.Web.Admin
{
	public partial class login : System.Web.UI.Page
	{
		Ajax.BLL.Admin bll = new Ajax.BLL.Admin();
		protected void Page_Load(object sender, EventArgs e)
		{
			DESEncrypt.Decrypt("50ADA460A6D0674B");
		}

		protected void loginsubmit_Click(object sender, ImageClickEventArgs e)
		{
			string UserName = txtUserName.Text.Trim();
			string UserPwd = txtUserPwd.Text.Trim();

			if (UserName.Equals("") || UserPwd.Equals(""))
			{
				lbMsg.Text = "请输入您要登录用户名或密码";
			}
			else
			{
				// 加密处理
				UserPwd = DESEncrypt.Encrypt(UserPwd);	

				if (Session["AdminLoginSun"] == null)
				{
					Session["AdminLoginSun"] = 1;
				}
				else
				{
					Session["AdminLoginSun"] = Convert.ToInt32(Session["AdminLoginSun"]) + 1;
				}
				//判断登录
				if (Session["AdminLoginSun"] != null && Convert.ToInt32(Session["AdminLoginSun"]) > 3)
				{
					lbMsg.Text = "登录错误超过3次，请关闭浏览器重新登录。";
				}
				else if (bll.chkAdminLogin(UserName, UserPwd))
				{
					Ajax.Model.Admin model = new Ajax.Model.Admin();
					model = bll.GetModel(UserName);
					Session["AdminNo"] = model.Id;
					Session["AdminName"] = model.UserName;
					Session["AdminType"] = model.UserType;
					Session["AdminLevel"] = model.UserLevel;
					//设置超时时间
					Session.Timeout = 45;
					Session["AdminLoginSun"] = null;
					Response.Redirect("admin_index.aspx");
				}
				else
				{
					lbMsg.Text = "您输入的用户名或密码不正确";
				}
			}
		}
	}
}
